<template>
	<view class="main">

		<tou_hand1 handtitle='修改管理员'></tou_hand1>
		<view class="show">
			<view class="sone">
				<view class="soneleft">姓名:</view>
				<input placeholder="请输入姓名，4个字符内" v-model="name"/>
			</view>
			<view class="sone">
				<view class="soneleft">分成比例：</view>
				<input placeholder="0" v-model="proportion" type="digit" />
			</view>
			<view class="stwo">
				<view class="stwoleft">
					开通权限：
				</view>
				<view class="stworight">
					<checkbox-group @change="checkboxChange">
						<label>
							<checkbox value="a" class="mont" :checked="charInArray('a', result) ? true:false" />设备管理
						</label>
						<label>
							<checkbox value="b" class="mont" :checked="charInArray('b', result) ? true:false" />运营统计
						</label>
						<label>
							<checkbox value="c" class="mont" :checked="charInArray('c', result) ? true:false" />注册用户
						</label>
					</checkbox-group>

				</view>
			</view>
			<view class="sthree">
				<view class="sthreehand" @click="okbtn">
					确认
				</view>
				<view class="sthreefoot">
					<view class="sthreeleft">
						提示：
					</view>
					<view class="sthreeright">
						1.分成比例上限{{num}}，请输入0-{{num}}之间的小数；最大保留3位小数;<br/>
						2.真实姓名请在个人资料中设置，否则影响提现
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import tou_hand1 from '../../components/tou_hand1/tou_hand1.vue'
	
	export default {
		components: {tou_hand1},
		mounted() {
			
		},

		data() {
			return {
				 result: [],
				 projectId:"",
				 name:'',//联系人
				 proportion:'',//管理员分成比例
				 deviceSettings:0,
				 totalSetting:0,
				 userSettings:0,
				 id:'',
				 num:'',
			}
		},
		onLoad(options) {
			// this.projectId=options.projectId
			this.name=options.name
			this.proportion=options.proportion
			this.projectId=options.projectId
			this.num=Number(options.num) + Number(options.proportion) 
			this.id=options.id
			
			if(options.deviceSettings==1){
				this.result.push('a');
			}
			if(options.totalSetting==1){
				this.result.push('b');
			}
			if(options.userSettings==1){
				this.result.push('c');
			}
		},
		methods: {
			charInArray(char, array) {
			    return array.includes(char);
			},
			checkboxChange: function (e) {
				console.log(e.detail.value);
				var result = e.detail.value;
				this.result = result;
			},
			okbtn(){
				let that = this;
				console.log(that.result);
				for(var i=0;i<that.result.length;i++){
					if(that.result[i]=='a'){
						that.deviceSettings=1
					}
					if(that.result[i]=='b'){
						that.totalSetting=1
					}
					if(that.result[i]=='c'){
						that.userSettings=1
					}
				}
				if(!that.name||!that.proportion){
					uni.showToast({
						title: '请完善信息',
						duration: 2000,
						icon: 'none'
					});
					return
				}
				if(Number(that.proportion) >that.num){
					uni.showToast({
						title: '分成比例超出上限，请修改后再试；',
						duration: 2000,
						icon: 'none'
					});
					return
				}
				
				// var userId=String.Format("{0:D8}", parseInt(this.userId))
				function PrefixZero(num, n) {
				    return (Array(n).join(0) + num).slice(-n);
				}
				let data={
					projectId:that.projectId,
					deviceSettings:that.deviceSettings,
					totalSetting:that.totalSetting,
					userSettings:that.userSettings,
					name:that.name,
					proportion:that.proportion,
					id:that.id
				}
				that.$base.request1('manager/projectManager', 'PUT',data)
					.then(res => {
						if(res.data.code==200){
							uni.showToast({
								title: res.data.msg,
								duration: 2000
							});
							uni.navigateBack()
						}else{
							uni.showToast({
								title: res.data.msg,
								duration: 2000,
								icon: 'none'
							});
						}
					})
					.catch(err => {
				
					})
			}
			
		}
	}
</script>

<style lang="scss" scoped>
	.main {
		width: 100%;
		overflow-x: hidden;
		
		.show{
			width: 100%;
			box-sizing: border-box;
			padding: 0 32upx;
			.sone{
				width: 100%;
				display: flex;
				border-bottom:1upx solid #dadada;
				padding-bottom: 27upx;
				align-items: center;
				margin-top: 27upx;
				.soneleft{
					font-size: 24upx;
					font-family: PingFang SC Regular, PingFang SC Regular-Regular;
					font-weight: 400;
					color: #333333;
					width: 37%;
				}
				input{
					font-size: 28upx;
					font-family: PingFang SC Regular, PingFang SC Regular-Regular;
					font-weight: 400;
					color: #999999;
				}
				.soneright{
					font-size: 28upx;
					font-family: PingFang SC Regular, PingFang SC Regular-Regular;
					font-weight: 400;
					color: #999999;
				}
			}
			.stwo{
				width: 100%;
				display: flex;
				border-bottom:1upx solid #dadada;
				padding-bottom: 27upx;
				align-items: center;
				margin-top: 27upx;
				.stwoleft{
					font-size: 24upx;
					font-family: PingFang SC Regular, PingFang SC Regular-Regular;
					font-weight: 400;
					color: #333333;
				}
				.stworight{
					/deep/.van-checkbox-group{
						display: flex;
						justify-content: space-between;
					}
					/deep/.van-checkbox__label {
						margin-left: 6upx;
					}
					/deep/.van-checkbox{
						margin-left: 20upx;
					}
					.mont{
						width: 120upx;
						// line-height: 40upx;
						font-size: 24upx;
						font-family: PingFang SC Medium, PingFang SC Medium-Medium;
						font-weight: 500;
						color: #333333;
					}
				}
				
			}
			.sthree{
				width: 100%;
				box-sizing: border-box;
				margin-top: 178upx;
				.sthreehand{
					width: 686upx;
					height: 88upx;
					border-radius: 8upx;
					line-height: 88upx;
					font-size: 32upx;
					font-family: PingFang SC Bold, PingFang SC Bold-Bold;
					font-weight: 700;
					text-align: center;
					color: #ffffff;
					margin: 0 auto;
					background-color: #4B98ED;
				}
				.sthreefoot{
					width: 100%;
					box-sizing: border-box;
					display: flex;
					margin-top: 32upx;
					line-height: 40upx;
					.sthreeleft{
						font-size: 24upx;
						font-family: PingFang SC Medium, PingFang SC Medium-Medium;
						font-weight: 500;
						color: #333333;
						width: 20%;
					}
					.sthreeright{
						font-size: 24upx;
						font-family: PingFang SC Medium, PingFang SC Medium-Medium;
						font-weight: 500;
						color: #666666;
					}
				}
			}
		}
		
	}
</style>
